/**
	Pulsar engine. Core.
	Additional include file. Advanced commnand line processing.

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.
		
	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

namespace pl
{

/**
	Advanced command line parser
*/
class CmdLineParser
{
public:
	/// Ctor
	explicit CmdLineParser(const CommandLine* pCmdLine, const pl_char* allowedOptionsChars = PL_T("/-")) :
	_pCmdLine(pCmdLine),
	_currentArg(0),
	_allowedOptionsChars(allowedOptionsChars)
	{
		return;
	}

	/// Get next argument
	bool getNext(const pl_char*& arg, bool &isOption);

	/// Get next option
	inline bool getNextOpt(const pl_char*& arg)
	{
		bool isOption;
		if (!getNext(arg, isOption) || !isOption)
		{
			return false;
		}
		return true;
	}

	/// Get next argument without processing
	inline bool getNextArg(const pl_char*& arg)
	{
		bool isOption;
		if (!getNext(arg, isOption) || isOption)
		{
			return false;
		}
		return true;
	}

	/// Get next argument (string style)
	template <pl_uint32 N> bool getNext(pl::String<N>& arg, bool &isOption)
	{
		const pl_char* argTemp;

		if (!getNext(argTemp, isOption))
		{
			return false;
		}
		arg.setSafe(argTemp);
		return true;
	}

	/// Get next argument (string style)
	template <pl_uint32 N> bool getNextArg(pl::String<N>& arg)
	{
		const pl_char* argTemp;

		if (!getNextArg(argTemp))
		{
			return false;
		}
		arg.setSafe(argTemp);
		return true;
	}

	/// Get next argument (string style)
	template <pl_uint32 N> bool getNextOpt(pl::String<N>& arg)
	{
		const pl_char* argTemp;

		if (!getNextOpt(argTemp))
		{
			return false;
		}
		arg.setSafe(argTemp);
		return true;
	}

private:
	/// Command line
	const CommandLine* _pCmdLine;
	/// Current argument in list
	pl_uint32 _currentArg; 
	/// List of allowed options dash
	const pl_char* _allowedOptionsChars;
};

} // namespace pl 

//
// End of file 'pulsar_cmdline.h'
//
